import type { CascaderItemDetailResult, CascaderItemEntityReq, CascaderItemOptionResult, CascaderItemTreeListResult, CascaderItemTreeResult } from "@/api/types";
import request from "@/utils/http";

/** 新增级联字典项 */
function create(data: CascaderItemEntityReq): Promise<Resp<string>> {
    return request({
        url: "/sys/cascaderItem/create",
        method: "post",
        data,
    });
}

/** 删除级联字典项 */
function remove(code: string, typeId: string): Promise<Resp<null>> {
    return request({
        url: "/sys/cascaderItem/remove",
        method: "post",
        data: { code, typeId },
    });
}

/** 修改级联字典项 */
function update(data: CascaderItemEntityReq): Promise<Resp<null>> {
    return request({
        url: "/sys/cascaderItem/update",
        method: "post",
        data,
    });
}

/** 查看级联字典项 */
function findById(id: string): Promise<Resp<CascaderItemDetailResult>> {
    return request({
        url: "/sys/cascaderItem/findById",
        method: "get",
        params: { id },
    });
}

/** 根据code查询路径 */
function findPathByCode(code: string): Promise<Resp<CascaderItemOptionResult[]>> {
    return request({
        url: "/sys/cascaderItem/findPathByCode",
        method: "get",
        params: { code },
    });
}

/** 获取级联选项 */
function listOptions(typeCode: string): Promise<Resp<CascaderItemTreeResult[]>> {
    return request({
        url: "/sys/cascaderItem/listOptions",
        method: "get",
        params: { typeCode },
    });
}

/** 查询树形列表 */
function listTree(typeCode: string): Promise<Resp<CascaderItemTreeListResult[]>> {
    return request({
        url: "/sys/cascaderItem/listTree",
        method: "get",
        params: { typeCode },
    });
}

export const cascaderItemApi = {
    create,
    remove,
    update,
    findById,
    findPathByCode,
    listOptions,
    listTree,
};
